package org.apache.dolphinscheduler.api.controller;

import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TYPE_ERROR;

import org.apache.dolphinscheduler.api.aspect.AccessLogAnnotation;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.TypeService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "TYPE_TAG")
@RestController
@RequestMapping("/type")
public class TypeController extends BaseController {

	@Autowired
	private TypeService typeService;
	
	@Operation(summary = "queryType", description = "QUERY_TYPE_NOTE")
    @Parameters({
            @Parameter(name = "type", description = "TYPE", required = true, schema = @Schema(implementation = Integer.class))
    })
    @GetMapping("/list")
    @ApiException(QUERY_TYPE_ERROR)
    @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
	public Result queryTypeList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
			@RequestParam(value = "type") int type) {
		return Result.success(typeService.queryTypeList(type));
	}
}
